package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.domain.po.Message;
import com.example.springboot.service.MessageService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @Author：伐柯梦姝
 * @Package：com.example.springboot.controller
 * @Project：springboot
 * @name：MessageController
 * @Date：2025/3/4 22:43
 * @Filename：MessageController
 * @for:
 */
@Api(tags = "留言管理接口")
@RestController
@CrossOrigin
@RequestMapping("/message")
public class MessageController {

       @Resource
       private MessageService messageService;

       /**
        * 描述：新增
        */
       @PostMapping
       public Result add(@RequestBody Message message) {
              messageService.add(message);
              return Result.success(message);
       }

       /**
        * 描述：根据ID删除
        */
       @DeleteMapping("/{id}")
       public Result delete(@PathVariable Integer id) {
              messageService.delete(id);
              return Result.success();
       }

       /**
        * 描述：查询所有
        */
       @GetMapping
       public Result all() {
              return Result.success(messageService.findAll());
       }

       /**
        * 描述：分页查询
        */
       @PostMapping("/page")
       public Result page(@RequestBody Message search,
                          @RequestParam(defaultValue = "1") Integer pageNum,
                          @RequestParam(defaultValue = "5") Integer pageSize) {
              return Result.success(messageService.findPage(search, pageNum, pageSize));
       }
}

